home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 19 / Amiga Plus Leser CD 19.iso / Online / AmigaTalk / intuition / IFF.st < prev    next >
Text File  |  2002-01-29  |  9KB  |  277 lines

  1. " ----------------------------------------------------------------------- "
  2. " The BasicIFF Class interfaces AmigaTalk to the iffparse.library.  See   "
  3. " class IDNumbers in IFFConstants.st file for valid ID numbers that       "
  4. " identify valid IFF chunks that IFF files & Objects contain.             "
  5. ""
  6. "    EXAMPLE:  16r424F4459 is 'BODY'                                      "
  7. ""
  8. " You should have access to the documentation for iffparse.library (or    "
  9. " wait for me to write some examples of how to use this Class ;).  I'm    "
  10. " NOT going to re-hash the IFF documentation for iffparse.library.  The   "
  11. " Help directory is getting complicated as it is.                         "
  12. " ----------------------------------------------------------------------- "
  13.  
  14. Class BasicIFF :Object ! private !
  15. [
  16.    closeIFF
  17.       <primitive 240 0 0 private>
  18. |
  19.    openIFF: iffFileName type: fileType mode: mode ! chk !
  20.  
  21.       " fileType here means: 0 for a file, & 1 for a clipboard. 
  22.       * mode is either #IFFF_READ, IFFF_WRITE or IFFF_RWBITS:
  23.       "
  24.       chk <- <primitive 240 0 1 iffFileName fileType mode>.
  25.  
  26.       (chk isNil)
  27.          ifTrue: ['Did NOT openIFF (nil returned!).' print.
  28.  
  29.                    ^ nil
  30.                  ].
  31.       
  32.       ^ private <- chk
  33. |
  34.    initIFFHook: hookObj flags: flags 
  35.       <primitive 240 1 0 private hookObj flags>
  36. |
  37.    initIFFAsDOS
  38.       <primitive 240 1 1 private>
  39. |
  40.    initIFFAsClip
  41.       <primitive 240 1 2 private>
  42. |
  43.    closeClipboard
  44.       <primitive 240 2 0 private>
  45. |
  46.    openClipboard: clipUnitNumber  " Range for clipUnitNumber is 0 to 255 "
  47.       ^ <primitive 240 2 1 private clipUnitNumber>
  48. |
  49.    parseIFF: mode
  50.       " Control modes for parseIFF method:
  51.       * #IFFPARSE_SCAN
  52.       * #IFFPARSE_STEP
  53.       * #IFFPARSE_RAWSTEP
  54.       "
  55.       ^ <primitive 240 2 2 private mode>
  56. |
  57.    readChunkBytes: byteArray size: numBytes
  58.       ^ <primitive 240 2 3 private byteArray numBytes>
  59. |
  60.    readChunkRecords: byteArray size: numBytes number: numRecords
  61.       ^ <primitive 240 2 4 private byteArray numBytes numRecords>
  62. |
  63.    writeChunkBytes: byteArray size: numBytes
  64.       ^ <primitive 240 2 5 private byteArray numBytes>
  65. |
  66.    writeChunkRecords: byteArray size: numBytes number: numRecords
  67.       ^ <primitive 240 2 6 private byteArray numBytes numRecords>
  68. |
  69.    stopChunk: type id: id
  70.       " The most common types are: 
  71.       *   #ID_ILBM, #ID_FTXT, #ID_SMUS, #ID_8SVX, #ID_ANIM
  72.       *
  73.       * See IDNumbers Class in IFFConstants.st for id values.
  74.       "
  75.       ^ <primitive 240 2 7 private type id>
  76. |
  77.    stopChunksWith: propertyArray size: numPairs
  78.       " Do a bunch of stopChunk settings at once.
  79.       *
  80.       * The propertyArray is constructed as follows:
  81.       * ele[1] <- type,     ele[2] <- id,
  82.       * ele[3] <- nextType, ele[4] <- nextid,
  83.       * ...
  84.       "
  85.       ^ <primitive 240 2 16 private propertyArray numPairs>
  86. |
  87.    currentChunk
  88.       ^ <primitive 240 2 8 private>
  89. |
  90.    propertyChunk: type id: id
  91.       ^ <primitive 240 2 9 private type id>
  92. |
  93.    propertyChunksWith: propertyArray size: numPairs
  94.       " Do a bunch of propertyChunk settings at once.
  95.       *
  96.       * The propertyArray is constructed as follows:
  97.       * ele[1] <- type,     ele[2] <- id,
  98.       * ele[3] <- nextType, ele[4] <- nextid,
  99.       * ...
  100.       "
  101.       ^ <primitive 240 2 17 private propertyArray numPairs>
  102. |
  103.    findProperty: type id: id
  104.       ^ <primitive 240 2 10 private type id>
  105. |
  106.    collectionChunk: type id: id
  107.       ^ <primitive 240 2 11 private type id>
  108. |
  109.    collectionChunksWith: propertyArray size: numPairs
  110.       " Do a bunch of collectionChunk settings at once.
  111.       * The propertyArray is constructed as follows:
  112.       *
  113.       * ele[1] <- type,     ele[2] <- id,
  114.       * ele[3] <- nextType, ele[4] <- nextid,
  115.       * ...
  116.       "
  117.       ^ <primitive 240 2 18 private propertyArray numPairs>
  118. |
  119.    findCollection: type id: id
  120.       ^ <primitive 240 2 12 private type id>
  121. |
  122.    stopOnExit: type id: id
  123.       ^ <primitive 240 2 13 private type id>
  124. |
  125.    addEntryHandlerHook: hookObj for: anObject type: type id: id position: pos
  126.       ^ <primitive 240 2 14 private hookObj anObject type id pos>
  127. |
  128.    addExitHandlerHook: hookObj for: anObject type: type id: id position: pos
  129.       ^ <primitive 240 2 15 private hookObj anObject type id pos>
  130. |
  131.    pushChunk: type id: id size: size
  132.       " size can also be #IFFSIZE_UNKNOWN if you dont know the size "
  133.       ^ <primitive 240 3 0 private type id size>
  134. |
  135.    popChunk
  136.       ^ <primitive 240 3 1 private>
  137. |
  138.    parentChunk
  139.       ^ <primitive 240 3 2 private>
  140. |
  141.    allocateLocalItem: ident type: type id: id size: dataSize
  142.       ^ <primitive 240 4 0 private type id ident dataSize>
  143. |
  144.    getLocalItemData
  145.       ^ <primitive 240 4 1 private>
  146. |
  147.    storeLocalItem: position
  148.       ^ <primitive 240 4 2 private position>
  149. |
  150.    storeItemInContext
  151.       <primitive 240 4 3 private>
  152. |
  153.    findPropertyContext
  154.       ^ <primitive 240 4 4 private>
  155. |
  156.    findLocalItem: ident type: type id: id
  157.       ^ <primitive 240 4 5 private type id ident>
  158. |
  159.    freeLocalItem
  160.       <primitive 240 4 6 private>
  161. |
  162.    setLocalItemPurge: hookObj
  163.       <primitive 240 4 7 private hookObj>
  164. |
  165.    getErrorString: errorNumber
  166.       ^ <primitive 240 5 errorNumber>
  167. |
  168.    idToString: identifier
  169.       ^ <primitive 240 6 identifier>
  170. |
  171.    getPropertySize: propertyObject
  172.       ^ <primitive 240 7 0 propertyObject>
  173. |
  174.    getPropertyData: propertyObject
  175.       ^ <primitive 240 7 1 propertyObject>
  176. |
  177.    getCollectionSize: collectionObject
  178.       ^ <primitive 240 8 0 collectionObject>
  179. |
  180.    getCollectionData: collectionObject
  181.       ^ <primitive 240 8 1 collectionObject>
  182. ]
  183.  
  184. " ----------------------------------------------------------------------- "
  185. " The ExamineIFF Class allows the User to obtain various chunks from an   "
  186. " IFF file (NOT clipboards).                                              "
  187. " ----------------------------------------------------------------------- "
  188.  
  189. Class ExamineIFF :BasicIFF ! dataTypeSystem ilbm rmode form body ftxt !
  190. [
  191.    initialize
  192.       dataTypeSystem <- DataTypeSystem new.
  193.       body           <- dataTypeSystem getIFFConstant: #ID_BODY.
  194.       form           <- dataTypeSystem getIFFConstant: #ID_FORM.
  195.       ilbm           <- dataTypeSystem getIFFConstant: #ID_ILBM.
  196.       ftxt           <- dataTypeSystem getIFFConstant: #ID_FTXT.
  197.       rmode          <- dataTypeSystem getIFFConstant: #IFFF_READ.
  198.  
  199.       ^ self
  200. |
  201.    privateObtainChunk: chunkType from: fileName id: chunkID parent: pID ! iffObj chk rval !
  202.       
  203.       iffObj <- super openIFF: fileName type: 1 mode: rmode.
  204.       
  205.       iffObj initIFFAsDOS.
  206.       
  207.       chk <- iffObj propertyChunk: chunkType id: chunkID. " Look for this chunk "
  208.       
  209.       (chk ~= 0 or: [chk isNil])
  210.          ifTrue: [ (iffObj getErrorString: chk) print.
  211.                    iffObj closeIFF.
  212.                    ^ nil
  213.                  ].
  214.          
  215.       chk <- iffObj stopChunk: chunkType id: pID.
  216.  
  217.       (chk ~= 0 or: [chk isNil])
  218.          ifTrue: [ (iffObj getErrorString: chk) print.
  219.                    iffObj closeIFF.
  220.                    ^ nil
  221.                  ].
  222.  
  223.       chk <- iffObj parseIFF: (dataTypeSystem getIFFConstant: #IFFPARSE_SCAN).
  224.  
  225.       (chk ~= 0 or: [chk isNil])
  226.          ifTrue: [ (iffObj getErrorString: chk) print.
  227.                    iffObj closeIFF.
  228.                    ^ nil
  229.                  ].
  230.  
  231.       rval <- iffObj findProperty: chunkType id: chunkID.
  232.  
  233.       (rval isNil)
  234.          ifTrue: [ 'NO bitmap header found!' print.
  235.                    iffObj closeIFF.
  236.                    ^ nil
  237.                  ].
  238.          
  239.       iffObj closeIFF.
  240.  
  241.       ^ rval
  242. |
  243.    obtainBMHD: fileName ! bmhd !
  244.       bmhd <- dataTypeSystem getIFFConstant: #ID_BMHD.
  245.       
  246.       ^ self privateObtainChunk: ilbm from: fileName id: bmhd parent: body
  247. |
  248.    obtainCMAP: fileName ! cmap !
  249.       cmap <- dataTypeSystem getIFFConstant: #ID_CMAP.
  250.       
  251.       ^ self privateObtainChunk: ilbm from: fileName id: cmap parent: body
  252. |
  253.    obtainCAMG: fileName ! camg !
  254.       camg <- dataTypeSystem getIFFConstant: #ID_CAMG.
  255.       
  256.       ^ self privateObtainChunk: ilbm from: fileName id: camg parent: body
  257. |
  258.    obtainPixelData: fileName
  259.       ^ self privateObtainChunk: ilbm from: fileName id: body parent: form
  260. |
  261.    obtainCHRS: fileName ! chrs !
  262.       chrs <- dataTypeSystem getIFFConstant: #ID_CHRS.
  263.       
  264.       ^ self privateObtainChunk: ftxt from: fileName id: chrs parent: form
  265. |
  266.    obtainVHDR: fileName ! vhdr svx8 !
  267.       svx8 <- dataTypeSystem getIFFConstant: #ID_8SVX.
  268.       vhdr <- dataTypeSystem getIFFConstant: #ID_VHDR.
  269.       
  270.       ^ self privateObtainChunk: svx8 from: fileName id: vhdr parent: form
  271. |
  272.    obtainVoiceData: fileName ! svx8 !
  273.       svx8 <- dataTypeSystem getIFFConstant: #ID_8SVX.
  274.       
  275.       ^ self privateObtainChunk: svx8 from: fileName id: body parent: form
  276. ]
  277.